import com.sun.javafx.collections.MappingChange;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Work07 {

    static class S implements Comparable<S>{
        int num;
        int sum;
        public S(int num, int sum) {
            this.num = num;
            this.sum = sum;
        }
        @Override
        public int compareTo(S o) {
            if(this.num != o.num){
                return this.sum - o.sum;
            }else{
                return this.num - o.num;
            }
        }
        @Override
        public String toString() {
            return "S{" +
                    "num=" + num +
                    ", sum=" + sum +
                    '}';
        }
    }

    static int sumOfBit(int num){
        int sum = 0;
        while(num > 0){
            int tmp = num % 10;
            sum += tmp;
            num /= 10;
        }
        return sum;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int a,b;
        a = scan.nextInt();
        b = scan.nextInt();
        S[] arr = new S[a];
        for(int i = 1;i<=a;i++){
            arr[i - 1] = new S(i,sumOfBit(i));
        }
        Arrays.sort(arr);
        /*for (int i = 0; i < a; i++) {
            System.out.println(arr[i]);
        }*/
        System.out.println(arr[b-1].num);


        scan.close();
    }
}
